package com.sl.springboot.service.impl;

import com.sl.springboot.dao.OrdersDao;
import com.sl.springboot.model.Orders;
import com.sl.springboot.model.PageInfo;
import com.sl.springboot.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.sl.springboot.util.RandomIdUtil;

/**
 * 用户Service接口实现类
 * @author: mty
 */
@Service("ordersService")
@Transactional
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersDao ordersDao;


    //分页查询
    @Override
    public PageInfo<Orders> findPageInfo(Integer pageIndex, Integer pageSize,Map mp) {
        PageInfo<Orders> pi = new PageInfo<Orders>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        mp.put("currentPage",(pi.getPageIndex()-1)*pi.getPageSize());
        mp.put("pageSize",pi.getPageSize());
        //获取总条数
        Integer totalCount = ordersDao.totalCount(mp);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //按条件查询
            List<Orders> ordersList =	ordersDao.getOrdersList(mp);
            pi.setList(ordersList);
        }
        return pi;
    }


    //添加
    @Override
    public int addOrders(Orders orders) {
        orders.setId(RandomIdUtil.getRandomIdByUUID());
        return ordersDao.addOrders(orders);
    }


    //根据id删除
    @Override
    public int deleteOrders(String id) {
        return ordersDao.deleteOrders(id);
    }


    //修改宿舍信息
    @Override
    public int updateOrders(Orders orders) {
        return ordersDao.updateOrders(orders);
    }

    //根据ID查询
    @Override
    public Orders findOrdersById (String id){
        Orders d = ordersDao.findOrdersById(id);
        return  d;
    }

    //查询所有
    @Override
    public List<Orders> getAll(){
        List<Orders> ordersList = ordersDao.getAll();
        return ordersList;
    }

    //按照条件查询
    @Override
    public List<Orders> queryFilter(Map mp){
        List<Orders> ordersList = ordersDao.queryFilter(mp);
        return ordersList;
    }
}
